package com.common.baselibrary.rxjava2.utils;

import java.io.File;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class FileReqParams {
    /*单文件或多文件上传*/
    public static RequestBody create(List<File> files, String mimeType) {
        MultipartBody.Builder builder = new MultipartBody.Builder()
                .setType(MultipartBody.FORM);
        for (File file : files) {
            builder.addFormDataPart("file[]", file.getName(),
                    RequestBody.create(MediaType.parse(mimeType), file));
        }
        return builder.build();
    }

    public static RequestBody create(File file, String mimeType) {
        MultipartBody.Builder builder = new MultipartBody.Builder()
                .setType(MultipartBody.FORM);
            builder.addFormDataPart("file", file.getName(),
                    RequestBody.create(MediaType.parse(mimeType), file));

        return builder.build();
    }
}
